package com.kangye.game.controller;

import com.alibaba.fastjson.JSON;
import com.kangye.game.pojo.Game;
import com.kangye.game.service.GamePriceService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 15832
 * @Description TODO
 * @Date 2021/9/1 10:41
 * @Version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/lbt")
public class GamePriceController {

    @Resource
    private GamePriceService gamePriceService;

    @GetMapping("/getPrice")
    public Map<String,String> getPrice(){
        Map<String,String> map = new HashMap<>();
        List<Game> list = gamePriceService.getGameShow();
        if (list != null){
            String data = JSON.toJSONString(list);
            map.put("code","200");
            map.put("data",data);
        }else {
            map.put("code","400");
        }
        return map;
    }


    @GetMapping("/gotoPrice")
    public Map<String,String> gotoPrice(String id){
        Map<String,String> map = new HashMap<>();
        Game game = gamePriceService.getGame(id);
        if (game != null){
            String data = JSON.toJSONString(game);
            map.put("code","200");
            map.put("game",data);
            List<Game> task = gamePriceService.getTask(id);
            if (task != null){
                String taskStr = JSON.toJSONString(task);
                map.put("task",taskStr);
            }
        }else {
            map.put("code","400");
        }
        return map;
    }


}
